<?php

namespace app\api\middleware;
use app\api\model\rbac\Admin;
use app\Request;
use think\facade\View;

/**
 * 后台登录
 * Class Auth
 * User:于小涛
 * Date:2020/2/16
 * Time:16:06
 */
class AuthLoginMiddleware
{
    private $arr_exclude=array(
        'user/login'
    );
    public function handle($request, \Closure $next)
    {
        $str_path_info=strtolower($request->pathinfo());
        if (!in_array($str_path_info,$this->arr_exclude)) {
            if($request->has('token')&&!empty($request->param('token'))){
                $obj_admin_model = new Admin();
                $arr_admin_info=$obj_admin_model->where('token',$request->param('token'))->select()->toArray();
                if(empty($arr_admin_info)){
                    return output_data(array(), 'usernotlogin');
                }else{
                    $request->arr_admin_info=$arr_admin_info[0];
                }
            }else{
                return output_data(array(), 'usernotlogin');
            }
        }
        return $next($request);
    }
}
